<%@page import="java.io.PrintStream"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="ISO-8859-1"%>
<%@page import="myJDBC.lowLevel.*"%>
<%@page import="myJDBC.lowLevel.Objects"%>
<%@ page import="java.util.*"%>
<%@ page import="constants.ObjectTypeConstants"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
<%@include file="smallJsps/styles.jsp" %>
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@include file="smallJsps/bootstrapInclude.jsp" %>
</head>
<body>	
	<%@include file="smallJsps/logoutButton.jsp" %>
	<%@include file="smallJsps/checkAdmin.jsp" %>
	<div class="row-fluid">
		<div class="span6 offset2">
	<form action="SrvlCreateObject" name="form" method="POST">	
	
		<%//ÑÑÐ¾Ð±Ñ ÑÑÐ° jsp Ð¼Ð¾Ð³Ð»Ð° ÑÐ°Ð±Ð¾ÑÐ°ÑÑ Ñ Ð²Ð°ÑÐ¸Ð¼Ð¸, ÐµÐ¹ Ð½Ð°Ð´Ð¾ Ð¿ÐµÑÐµÐ´Ð°ÑÑ sel --Ð°Ð¹Ð´Ð¸ Ð¾Ð±ÑÐµÐºÑÐ½Ð¾Ð³Ð¾ ÑÐ¸Ð¿Ð° ÐºÐ°Ðº Ð¿Ð°ÑÐ°Ð¼ÐµÑÑ Ð¸Ð»Ð¸ Ð°ÑÑÑÐ¸Ð±ÑÑ
			int objid= -1;
			if(request.getParameter("sel")!=null || request.getAttribute("sel")!=null){
				if(request.getParameter("sel")==null)
					objid=Integer.parseInt(request.getAttribute("sel").toString());
				else
					objid=Integer.parseInt(request.getParameter("sel"));
				out.print("<input type=\"hidden\" name=\"objTypeId\" value="+objid+">");
				ArrayList<String> attrib = new ArrayList<String>();
				attrib = ObjectTypes.returnObjectType(objid);			
				int barier= attrib.indexOf(null);
				for(int i=0; i<=barier; i++)
					attrib.remove(0);
					
		%>
		<h3>Create <%=ObjectTypes.returnObjTypeName(objid)%></h3>
		
		<label>name<br><input type="text" name="name"></label><br>
	<label>description<br><textarea name="descr" cols="40" rows="3"></textarea></label><br>
	
		<%
		if(request.getParameter("par")!=null){
			int parentid=Integer.parseInt(request.getParameter("par"));
			out.print("<input type=\"hidden\" name=\"objParId\" value="+parentid+">");
		}else{
			 %>		 
			<label>parentObject<br><select name="objParId">
			<option selected="selected" value="-1">null</option>
				<% 
					ArrayList<String> al= new ArrayList<String>();
					al=Objects.returnAllObjInfo();
					for(int i=0;i<al.size();i+=2){
						out.println("<option value="+al.get(i)+">"+al.get(i+1)+"</option>");
					}
				%>
			</select></label>
		<%} %>
		
		<table class="table-striped table-condensed" border="1">
		<% 
			for(int i=0;i< attrib.size(); i=i+3){
				out.print("<tr>");
				out.print("<td>" + attrib.get(i+1) + "</td>");
				out.print("<td>" + attrib.get(i+2) + "</td>");
				out.print("<input type=\"hidden\" name=\"t"+attrib.get(i)+"\" value="+ attrib.get(i+2) +">");
				//ÑÐ¼Ð¾ÑÑÐ¸Ð¼ ÑÑÐ¾ Ð±ÑÐ´ÐµÑ Ð² 3 ÑÑÐ¾Ð»Ð±ÑÐµ
				if(attrib.get(i+2).equals(AttributeTypes.returnAttrType(2)) || attrib.get(i+2).equals(AttributeTypes.returnAttrType(1)))
					out.print("<td><input name="+attrib.get(i)+" type=\"text\"></td>");
				if(attrib.get(i+2).equals(AttributeTypes.returnAttrType(3))){			
					out.print("<td><label>DD-MM-YYYY<input name="+attrib.get(i)+" type=\"text\"></label></td>");
				}
				if(attrib.get(i+2).equals(AttributeTypes.returnAttrType(5))){
					int objtypeId=-1;
					switch (Integer.parseInt(attrib.get(i))) {
            			case 6:{ 
            				objtypeId=ObjectTypeConstants.group;//ref_gruop, group
            				break;
            			}
            			case 10:{
            				objtypeId=ObjectTypeConstants.country;//ref_country, county
            				break;
            			}
            			case 11:{
            			 	objtypeId=ObjectTypeConstants.city;//ref_city, city
            			 	break;
            			}
            			case 12:{
            			 objtypeId=ObjectTypeConstants.district;//ref_district, district
            				break;
            			}
            			case 13:{
            				 objtypeId=ObjectTypeConstants.street;//ref_street, street
            				break;
            			}
            			case 14:{
            				 objtypeId=ObjectTypeConstants.house;//ref_house, house
            				break;
            			}
            			case 15:{
            				 objtypeId=ObjectTypeConstants.porch;//ref_porch, porch
            				break;
            			}
            			case 16:{
            				 objtypeId=ObjectTypeConstants.apartment;//ref_apartment, apartment
            				break;
            			}
            			case 18:{
            				 objtypeId=ObjectTypeConstants.order;//ref_order, order
            				break;
            			}
            			case 20: {
	            			objtypeId=ObjectTypeConstants.task_manual;//ref_next_task, taskmanual
							ArrayList<String> al2=new ArrayList<String>();
							al2=Objects.returnObjInfoWithObjTypeID(objtypeId);
							out.print("<td><div class=\"btn-group\"><button data-toggle=\"dropdown\" class=\"btn dropdown-toggle\">check :<span class=\"caret\"></span></button><ul class=\"dropdown-menu\">");
							for(int j=0;j<al2.size();j+=2){
							
								out.print("<li><label><input type=\"checkbox\" ");  
								out.print("name=\""+attrib.get(i)+"\" value=\"" +al2.get(j)+ "\" > " +al2.get(j+1)+"</label></li>");
							}
							out.print("</ul></div></td>");
							//4ÑÑÐ¾Ð»Ð±ÐµÑ
							out.print("<td><a href=createObject2?sel="+objtypeId+">create new</a></td>");	         			
							objtypeId=ObjectTypeConstants.task_auto;//ref_next_task, taskauto
							break;
            			}
            			case 21:{
            				 objtypeId=ObjectTypeConstants.user;//ref_user, user
            				break;
            			}            			
            			case 53:{
            				 objtypeId=ObjectTypeConstants.customer;//ref_client, client
            				break;
            			}
            			case 25: {
            				objtypeId=ObjectTypeConstants.task_manual;//ref_next_task, taskmanual
	            			ArrayList<String> al2=new ArrayList<String>();
							al2=Objects.returnObjInfoWithObjTypeID(objtypeId);
							out.print("<td><div class=\"btn-group\"><button data-toggle=\"dropdown\" class=\"btn dropdown-toggle\">check :<span class=\"caret\"></span></button><ul class=\"dropdown-menu\">");
							for(int j=0;j<al2.size();j+=2){
							
								out.print("<li><label><input type=\"checkbox\" ");  
								out.print("name=\""+attrib.get(i)+"\" value=\"" +al2.get(j)+ "\" > " +al2.get(j+1)+"</label></li>");
							}
							out.print("</ul></div></td>");
							//4ÑÑÐ¾Ð»Ð±ÐµÑ
							out.print("<td><a href=createObject2?sel="+objtypeId+">create new</a></td>");	
            				objtypeId=ObjectTypeConstants.task_auto;//ref_next_task, taskauto
            				break;
            			}
            			case 26: {
            				objtypeId=ObjectTypeConstants.task_manual;//ref_next_on_yes , taskmanual
            				ArrayList<String> al2=new ArrayList<String>();
							al2=Objects.returnObjInfoWithObjTypeID(objtypeId);
							out.print("<td><div class=\"btn-group\"><button data-toggle=\"dropdown\" class=\"btn dropdown-toggle\">check :<span class=\"caret\"></span></button><ul class=\"dropdown-menu\">");
							for(int j=0;j<al2.size();j+=2){
							
								out.print("<li><label><input type=\"checkbox\" ");  
								out.print("name=\""+attrib.get(i)+"\" value=\"" +al2.get(j)+ "\" > " +al2.get(j+1)+"</label></li>");
							}
							out.print("</ul></div></td>");
							//4ÑÑÐ¾Ð»Ð±ÐµÑ
							out.print("<td><a href=createObject2?sel="+objtypeId+">create new</a></td>");	
            				objtypeId=ObjectTypeConstants.task_auto;//ref_next_on_no , taskauto
            				break;
            			}
            		}
					ArrayList<String> al2=new ArrayList<String>();
					al2=Objects.returnObjInfoWithObjTypeID(objtypeId);
					out.print("<td><div class=\"btn-group\"><button data-toggle=\"dropdown\" class=\"btn dropdown-toggle\">check :<span class=\"caret\"></span></button><ul class=\"dropdown-menu\">");
					for(int j=0;j<al2.size();j+=2){
					
						out.print("<li><label><input type=\"checkbox\" ");  
						out.print("name=\""+attrib.get(i)+"\" value=\"" +al2.get(j)+ "\" > " +al2.get(j+1)+"</label></li>");
					}
					out.print("</ul></div></td>");
					//4ÑÑÐ¾Ð»Ð±ÐµÑ
					out.print("<td><a href=createObject2?sel="+objtypeId+">create new</a></td>");					
				}				
				if(attrib.get(i+2).equals(AttributeTypes.returnAttrType(4))){
					out.print("<td><select name="+attrib.get(i)+">");
						ArrayList<String> al2=new ArrayList<String>();
						al2=AttrTypeDef.returnAtrListValues(Integer.parseInt(attrib.get(i)));
						for(int j=0;j<al2.size();j+=2){
							out.println("<option value="+al2.get(j)+">"+al2.get(j+1)+"</option>");
							
						}
					out.print("</select></td>");
				}
				
				
				
				out.print("</tr>");
			}
			%>				
		</table>
		<%}%>
		<input class="btn btn-large btn-primary" type="submit" value="Create <%=ObjectTypes.returnObjTypeName(objid)%>">
</form>
<form method="get" action="privateOffice"><button class="btn" type="submit">privateOffice</button></form>
</div>
</div>
</body>
</html>